class Solution(object):
    def maxDepth(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
        if not root:
            return 0
        else:
            layer = [[root], []]
            count = 0
            while len(layer[count % 2]) > 0:
                now_layer = layer[count % 2]
                count += 1
                next_layer = []
                for item in now_layer:
                    if item.left:
                        next_layer.append(item.left)
                    if item.right:
                        next_layer.append(item.right)
                layer[count % 2] = next_layer
            return count
